package com.kkk.shop.common.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import com.kkk.shop.common.util.DateFormatUtil;
import com.kkk.shop.common.util.PageInfoUtil;

/**
 * 所有Controller的父类,父类没有顶Controller子类有照样可用
 * @author kkk
 * */
public class BaseController
{
	//用于前台显示信息
	protected String info;
	//日期解析工具类
	@Resource
	protected DateFormatUtil dateFormatUtil;
	//设置参数的Map对象
	private Map<String,Object> paramMap=null;
	/**
	 * 处理分页工具类
	 * @param request
	 * @return PageInfoUtil
	 * */
	protected PageInfoUtil processPageInfo(HttpServletRequest request)
	{
		PageInfoUtil pageInfoUtil=new PageInfoUtil();
		try
		{
			String currentPage=request.getParameter("currentPage");
			String pageSize=request.getParameter("pageSize");
			pageInfoUtil.setCurrentPage(Integer.valueOf(currentPage));
			pageInfoUtil.setPageSize(Integer.valueOf(pageSize));
		} catch (NumberFormatException e)
		{//不处理异常,主要是担心前台用户乱输入数据出错
		}
		return pageInfoUtil;
	}
	/**
	 * 处理分页工具类
	 * @param request
	 * @return PageInfoUtil
	 * */
	protected PageInfoUtil proccedPageInfo(String currentPage, String pageSize)
	{
		PageInfoUtil pageInfoUtil = new PageInfoUtil();
		try
		{
			pageInfoUtil.setCurrentPage(Integer.valueOf(currentPage));
			pageInfoUtil.setPageSize(Integer.valueOf(pageSize));
		} catch (Exception e)
		{
		}
		return pageInfoUtil;
	}
	
	/**
	 * 获取设置参数的Map
	 * @return Map<String,Object>
	 * */
	protected Map<String,Object> getParamMap()
	{
		if(paramMap==null)
		{
			paramMap=new HashMap<String,Object>();
		}
		paramMap.clear();
		return paramMap;
	}
}
